#pragma once

#include "pch.h"
#include "prerequisites.h"
#include "scene_node.h"

class c_frustum
{
	friend class c_camera;

public:
    enum enum_frustum_side 
    {
        FRUSTUM_NEAR = 0,
        FRUSTUM_FAR, 
        FRUSTUM_TOP,
        FRUSTUM_BOTTOM,
        FRUSTUM_LEFT,
        FRUSTUM_RIGHT,
        FRUSTUM_NUM_PLANES
    };

    c_frustum(const float fov, const float aspect, const float near_plane, const float far_plane); 
    c_matrix4x4 get_projection_matrix() const;

private:
    float m_fov;
    float m_aspect;
    float m_near_plane;
    float m_far_plane;
   
    c_matrix4x4 m_mat_proj; 
};

class c_camera : public c_scene_node, public CFirstPersonCamera
{
public:
    c_camera(c_scene *scene_mgr, const std::string& name, const c_vector3& postion, const c_vector3& lookat, const c_vector3& up, const frustum_ptr& frustum = frustum_ptr()); 
    
    virtual bool update(c_scene *scene, const float dt);
    virtual void render(c_scene *scene);
   
    c_matrix4x4 get_view_proj();
    c_matrix4x4 get_view() const; 
    c_matrix4x4 get_proj() const; 

    void set_viewport(const D3DVIEWPORT9& vp) {m_viewport = vp;}
    D3DVIEWPORT9 get_viewport() const { return m_viewport; }
    
    void set_active(bool bact) { m_is_active = bact; }
    bool is_active() { return m_is_active; }

private:
    c_matrix4x4 m_mat_proj;
    c_matrix4x4 m_mat_view;
    
    frustum_ptr m_frustum;
    D3DVIEWPORT9 m_viewport; 
    
    bool m_is_active; 
};